package com.qf.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class TtlConfig {
    //创建交换机
    @Bean
    public DirectExchange createExchangeTtl(){
        return new DirectExchange("exchange_direct_ttl_demo");
    }


    //创建过期队列
    //设置队列过期时间为10000 10S钟
    @Bean
    public Queue createQueueTtl(){
        return QueueBuilder.durable("queue_ttl_demo").withArgument("x-message-ttl",10000).build();//队列设置：在队列申明的时候使用 x-message-ttl 参数，单位为 毫秒
    }

    //创建绑定
    @Bean
    public Binding createBindingTtl(){
        return BindingBuilder.bind(createQueueTtl()).to(createExchangeTtl()).with("item.ttl");

    }

}
